package com.e.dianshang.controller;

import com.e.dianshang.pojo.GetTicket;
import com.e.dianshang.service.GetTicketService;
import com.e.dianshang.service.OrderService;
import com.e.dianshang.utils.BusinessException;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Tian同學
 * @Date 2020/11/9 17:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/getTkt")
@Api(value = "领取优惠券",tags = "领取优惠券的api")
public class GetTicketController {

    @Resource
    GetTicketService getTicketService;

    @PostMapping("/getTktByName")
    @ApiOperation(value = "领取优惠券",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tktId",value = "优惠券id",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "openid",value = "微信id或用户手机",required = true,dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "brandId",value = "商品品牌id",required = true,dataType = "int",paramType = "query")
    })
    public Map getTktByName(@RequestParam("tktId") Integer tktId,@RequestParam("openid") String openid,@RequestParam("brandId") Integer brandId) throws BusinessException {

        JsonResult jsonResult=new JsonResult();
        GetTicket getTicket=new GetTicket();
        getTicket.setTktId(tktId);
        getTicket.setOpenid(openid);
        getTicket.setBrandId(brandId);
        int tktByName = getTicketService.getTktByName(getTicket);

        if (tktByName==1){
            jsonResult.setCode("0");
            jsonResult.setMsg("领取成功");
        }else {
            throw new BusinessException("领取失败");
        }

        return jsonResult.getValues();

    }

}
